loadFile_CSS_Link([
    "/Scripts/tools/IIconSVG.css"
]);

/** 图标使用SVG文件加载 */
class IconSVG implements IIconSVG {
    /**
     * 加载执行 .iconsvg 图标标记, 在属性中 data-svg="<url>" 写明svg地址
     * @param jqueryRegion 需要加载的区域范围JQuery类型表示
     */
    public async onload(jqueryRegion?: JQuery) {
        let isNotLoad: boolean = false;
        isNotLoad = (window as any).SVGInject && typeof (window as any).SVGInject === "function";
        if (!isNotLoad) {
            await import(ToResourceURL(EResourceID.LibraryOne, "/Scripts/svg-inject.js"));
        }
        jqueryRegion = jqueryRegion || $("body");
        let icons = jqueryRegion.find(".iconsvg");
        for (let index = 0; index < icons.length; index++) {
            const element = $(icons[index]);
            let svg = element.children("svg.svg");
            if (svg.length > 0) {
                continue;
            }
            let resourceid = element.attr("data-resourceid");
            let file_path = element.attr("src");
            if (!file_path) {
                continue;
            }
            if (resourceid) {
                let rid: EResourceID = Number(resourceid);
                file_path = ToResourceURL(rid, file_path);
            }
            let img = $(`<img class="svg" src="${file_path}" onload="SVGInject(this)" />`);
            element.prepend(img);
        }
    }
}

class ScriptTool_IIconSVG implements IScriptTool<IIconSVG> {
    GetCase(): IIconSVG {
        return new IconSVG();
    }
}

export default ScriptTool_IIconSVG;
